package com.ruicar.afs.cloud.archive.service.impl;

import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson.JSONObject;
import com.ruicar.afs.cloud.archive.feign.GetTokenFeign;
import com.ruicar.afs.cloud.archive.service.ArchiveService;
import com.ruicar.afs.cloud.archive.utils.GetTokenConfig;
import com.ruicar.afs.cloud.common.core.security.util.SecurityUtils;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @description: 归档接口
 * @author: sijun.yu
 * @date: 2020/8/6 21:18
 */
@Service
@AllArgsConstructor
public class ArchiveServiceImpl implements ArchiveService {

    private GetTokenFeign getTokenFeign;
    private GetTokenConfig getTokenConfig;

    /**
     * 获取token
     * @return
     */
    public String getAuthorization() {

        Map<String, String> data = new HashMap<>();
        data.put("client_id", getTokenConfig.getClientId());
        data.put("client_secret", getTokenConfig.getClientSecret());
        data.put("grant_type", getTokenConfig.getGrantType());
        data.put("username",SecurityUtils.getUser().getId().toString());
        data.put("password",SecureUtil.md5(SecurityUtils.getUser().getId().toString()));
        data.put("platform","");
        JSONObject jsonObject = getTokenFeign.getTokenInfo(data);
        String authorization = jsonObject.getString("token_type") + " " + jsonObject.getString("access_token");
        return authorization;
    }

}
